/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package groupchooser;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.HashMap;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;

/**
 *
 * @author Bartal Clementsen
 */
public class StudentsPane extends javax.swing.JPanel {

    /**
     * Creates new form StudentsPane
     */
    HashMap<JCheckBox,Student> list;
    public StudentsPane() {
        
        initComponents();
        this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
        populateFrame();
    }
    
    private void populateFrame()
    {
        list = new HashMap<JCheckBox, Student>();
        for(Student s : Handler.gch.getAllStudents())
        {
            JCheckBox jcb = new JCheckBox();
            jcb.setText(s.getFirstName());
            jcb.setSelected(s.getIsAttending());
            list.put(jcb, s);
            jcb.addItemListener(new ItemListener() {
                @Override
                public void itemStateChanged(ItemEvent e) {
                    if (e.getStateChange() == ItemEvent.SELECTED) {
                        list.get((JCheckBox)e.getItem()).setIsAttending(true);
                    } else {
                        list.get((JCheckBox)e.getItem()).setIsAttending(false);
                    }
                }
            });
            this.add(jcb);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
